<?php

class DefaultRuleParser extends RuleParser {
	
	public $config;
	public $roleDefines;
	
	public function parse() {
		
		$hState = $this->stateHandle;
		$value = $hState->getHandleValue();
		$ops = array();
		foreach($this->config as $role=>$allOps) {
			if($this->isRoleMatched($role)) {
				$ops = array_merge($ops, $this->match($allOps, $value));
			}
		}
		return $ops;
	}
	
	public function isRoleMatched($role) {
		if(!isset($this->roleDefines[$role])) return false;
		return $this->evaluateExpression($this->roleDefines[$role], array(
			'data' => $this->stateHandle->getOwner(),
		));
	}
	
	protected function match($ops, $value) {
		$operations = array();
		if(isset($ops[$value])) {
			$operations = array_merge($operations, $ops[$value]);
		}
		if(isset($ops['*'])) {
			$operations = array_merge($operations, $ops['*']);
		}
		return $operations;
	}
	
}

?>